﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;

namespace SchoolManagementSystem.Report._2._ThuQuy
{
    public partial class SoQuyTongHop : DevExpress.XtraReports.UI.XtraReport
    {
        public int TonDauKyVND;
        public int TonDauKyUSD;
        public SoQuyTongHop()
        {
            InitializeComponent();
        }
        public int a = 0;
        int indexgroup = 0;
        int lasttonvnd = 0;
        int lasttonusd = 0;
        int sumthuvn=0;
        int sumchivn=0;
        int sumthuusd=0;
        int sumchiusd=0;
        private void Detail_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            var code = GetCurrentColumnValue("ReceiptNo");
            var thuvn = GetCurrentColumnValue("MoneyThuVNInt");
            var thuusd = GetCurrentColumnValue("MoneyThuUSDInt");
            var chiusd = GetCurrentColumnValue("MoneyChiUSDInt");
            var chivn = GetCurrentColumnValue("MoneyChiVNInt");
            if (code != null)
            { 
                if(code.ToString().Contains("PTHP"))
                {
                    xrTableCell_ReceiptNoFee.Text = code.ToString();
                    xrTableCell_ReceiptNoSale.Text = "";
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_PaySchool.Text = "";
                }
                if (code.ToString().Contains("PTDC"))
                {
                    xrTableCell_ReceiptNoSale.Text = code.ToString();
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_PaySchool.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                }
                if (code.ToString().Contains("PTCH"))
                {
                    xrTableCell_ReceiptNoApartment.Text = code.ToString();         
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_PaySchool.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                    xrTableCell_ReceiptNoSale.Text = "";
                }
                if (code.ToString().Contains("PTSL"))
                {
                    xrTableCell_ReceiptNoSalon.Text = code.ToString();
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_PaySchool.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                    xrTableCell_ReceiptNoSale.Text = "";
                }
                if (code.ToString().Contains("PTNB"))
                {
                    xrTableCell_ReceiptNoLocal.Text = code.ToString();
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_PaySchool.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                    xrTableCell_ReceiptNoSale.Text = "";
                }
                if (code.ToString().Contains("PCCH"))
                {
                    xrTableCell_PayApartment.Text = code.ToString();
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_PaySchool.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                    xrTableCell_ReceiptNoSale.Text = "";
                }
                if (code.ToString().Contains("PCT"))
                {
                    xrTableCell_PaySchool.Text = code.ToString();
                    xrTableCell_ReceiptNoLocal.Text = "";
                    xrTableCell_ReceiptNoApartment.Text = "";
                    xrTableCell_ReceiptNoSalon.Text = "";
                    xrTableCell_PayApartment.Text = "";
                    xrTableCell_ReceiptNoFee.Text = "";
                    xrTableCell_ReceiptNoSale.Text = "";
                }

                sumchiusd += int.Parse(chiusd.ToString());
                sumchivn += int.Parse(chivn.ToString());
                sumthuusd += int.Parse(thuusd.ToString());
                sumthuvn += int.Parse(thuvn.ToString());


                lasttonvnd = int.Parse(GetCurrentColumnValue("MoneyInStockVN").ToString());
                lasttonusd = int.Parse(GetCurrentColumnValue("MoneyInStockUSD").ToString());

            }
        }

        private void GroupHeader1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            var month = GetCurrentColumnValue("Month");
            var year = GetCurrentColumnValue("Year");

            if (month != null && year != null)
            {
                xrTableCell_sodudauky.Text = "Số dư đầu kỳ tháng " + month + "/" + year;
            }
            indexgroup++;
            if (indexgroup == 1)
            {

                xrTableCell_tonVN.Text = Helper.StringHelper.FormatVND(TonDauKyVND);
                xrTableCell_TonUSD.Text = Helper.StringHelper.FormatCurrencyUS(TonDauKyUSD);
            }
            else
            {
                xrTableCell_tonVN.Text = Helper.StringHelper.FormatVND(lasttonvnd);
                xrTableCell_TonUSD.Text = Helper.StringHelper.FormatCurrencyUS(lasttonusd);
                
            }
        }

        private void GroupFooter1_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            var month = GetCurrentColumnValue("Month");
            var year = GetCurrentColumnValue("Year");
            xrTableCell_tongcongthang.Text ="Tổng cộng tháng "+month+"/"+year;
            xrTableCell_tongthuUSD.Text = Helper.StringHelper.FormatCurrencyUS(sumthuusd);
            xrTableCell_tongthuVN.Text = Helper.StringHelper.FormatVND(sumthuvn);
            xrTableCell_tongchiUSD.Text = Helper.StringHelper.FormatCurrencyUS(sumchiusd);
            xrTableCell_tongchiVN.Text = Helper.StringHelper.FormatVND(sumchivn);
            sumchivn = 0;
            sumchiusd = 0;
            sumthuvn = 0;
            sumthuusd = 0;
        }

    }
}
